package com.xquant.pricing.calc.service.impl.otcOption.split;

import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.alibaba.fastjson2.JSON;
import com.xquant.common.core.constant.DictConstant;
import com.xquant.pricing.calc.entity.CalcEngineParam4Simple;
import com.xquant.pricing.calc.entity.airbag.AirbagDTO;
import com.xquant.pricing.calc.entity.airbag.KnockIn;
import com.xquant.pricing.calc.entity.airbag.UnKnockIn;
import com.xquant.pricing.calc.entity.barrier.*;
import com.xquant.common.engine.xPP.request.CalcEngineParam;
import com.xquant.common.engine.xPP.request.Instrument;
import org.springframework.stereotype.Component;

import java.io.*;
import java.util.List;


@Component
public class CalcCommonService4OtcOptionSplit4Airbag implements CalcCommonService4OtcOptionSplit {

    @Override
    public CalcEngineParam split(CalcEngineParam4Simple sourceCalcEngineParam) {
        {

            return null;
        }
    }

    @Override
    public CalcEngineParam split(CalcEngineParam sourceCalcEngineParam) {

        CalcEngineParam engineParam = new CalcEngineParam();
        engineParam.setPriority("h");
        engineParam.setLocalLog("1");
        Instrument instrument = sourceCalcEngineParam.getInstrument();
        instrument.setProductType(DictConstant.PRODUCT_TYPE.STRATEGY);
        JSONObject termsheet = sourceCalcEngineParam.getInstrument().getTermsheet();
        JSONArray sourceCustomLegs = termsheet.getJSONArray("customLegs");
        String s = JSON.toJSONString(sourceCustomLegs.get(0));
        AirbagDTO airbagDTO = JSON.parseObject(s, AirbagDTO.class);
        String cap = airbagDTO.getCap();
        JSONArray customLegs = new JSONArray();
        JSONArray legs = new JSONArray();
        JSONObject leg01 = new JSONObject();
        JSONObject leg02 = new JSONObject();
        JSONObject leg03 = new JSONObject();
        JSONObject leg04 = new JSONObject();
        String payDirection = airbagDTO.getPayDirection();
        int payDirectionanInt = Integer.parseInt(payDirection);
        leg01.put("legId", "leg01");
        leg01.put("payDirection", airbagDTO.getPayDirection());
        leg02.put("legId", "leg02");
        leg02.put("payDirection", 0 - payDirectionanInt);
        leg03.put("legId", "leg03");
        leg03.put("payDirection", airbagDTO.getPayDirection());
        leg04.put("legId", "leg04");
        leg04.put("payDirection", 0 - payDirectionanInt);


//        leg01.put("payDirection", DictConstant.DIRECT.SELL);
        if (cap.equals("cap")) {
            customLegs = generateCap(termsheet, airbagDTO);
            legs.add(leg01);
            legs.add(leg02);
            legs.add(leg03);
            legs.add(leg04);
        } else {
            leg01.put("legId", "leg01");
            leg01.put("payDirection", airbagDTO.getPayDirection());
            leg02.put("legId", "leg02");
            leg02.put("payDirection", airbagDTO.getPayDirection());
            leg03.put("legId", "leg03");
            leg03.put("payDirection", 0 - payDirectionanInt);
            legs.add(leg01);
            legs.add(leg02);
            legs.add(leg03);
            customLegs = generateUnCap(termsheet, airbagDTO);
        }
        termsheet.put("legs", legs);
        termsheet.put("customLegs", customLegs);
        instrument.setTermsheet(termsheet);
        sourceCalcEngineParam.setInstrument(instrument);
        return sourceCalcEngineParam;
    }

    @Override
    public String getSplitCode() {
        return DictConstant.OPTION_TYPE.AIRBAG.getCode();
    }

    static List deepCopy(List srcList) {
        ByteArrayOutputStream byteOut = new ByteArrayOutputStream();

        try {
            ObjectOutputStream objectOut = new ObjectOutputStream(byteOut);
            objectOut.writeObject(srcList);
            ByteArrayInputStream byteInput = new ByteArrayInputStream(byteOut.toByteArray());
            ObjectInputStream objectInput = new ObjectInputStream(byteInput);
            return (List) objectInput.readObject();
        } catch (IOException | ClassNotFoundException e) {
            e.printStackTrace();
        }
        return null;
    }


    /*
     * cap  上端封顶  4个障碍
     * */
    private JSONArray generateCap(JSONObject termsheet, AirbagDTO airbagDTO) {
        BarrierOption barrierOption1 = new BarrierOption();
        BarrierOption barrierOption2 = new BarrierOption();
        BarrierOption barrierOption3 = new BarrierOption();
        BarrierOption barrierOption4 = new BarrierOption();
        KnockIn knockIn = airbagDTO.getKnockIn();
        UnKnockIn unKnockIn = airbagDTO.getUnKnockIn();
        Double notional = Double.valueOf(termsheet.get("notional").toString());
        String effectiveDate = termsheet.get("effectiveDate").toString();
        String terminationDate = termsheet.get("terminationDate").toString();
        List<Underlyers> underlyers = airbagDTO.getUnderlyers();
        underlyers.get(0).setFixingDate(terminationDate);

        ObserveDates observeDates = new ObserveDates()
                .setCalendar(airbagDTO.getPaymentDateCalendar())
                .setEndDateConv(airbagDTO.getSettlementDateConv())
                .setEndDate(terminationDate)
                .setStartDate(effectiveDate)
                .setStartDateConv(airbagDTO.getSettlementDateConv())
                .setFrequency(knockIn.getScheduleType());
        String s = JSON.toJSONString(observeDates);
        Double year = 1.0;
        if ("1".equals(airbagDTO.getMoneynessOption())) {
            Integer term = airbagDTO.getTerm();
            year = term / 365.0;
        }

        /*
        *
        * 类型：Down-Out-Call Option
          方向：买入
          障碍价格：敲入价格
          行权价格：低行权价格
          补偿金额：0
          有效名义本金（非年化）：名义本金*未敲入参与率
          有效名义本金（年化）：名义本金*未敲入参与率*计息天数/365
        * */
        Double realnotional1 = Double.parseDouble(unKnockIn.getParticipationRate()) * notional * year;
        barrierOption1
                .setRealnotional(String.valueOf(realnotional1))
                .setProductType(DictConstant.OPTION_TYPE.KnockOut.getCode())
                .setUnderlyers(deepCopy(underlyers))
                .setExercise(JSON.parseObject(JSON.toJSONString(airbagDTO.getExercise()), Exercise.class))
                .setMoneynessOption(airbagDTO.getMoneynessOption())
                .setFixingRounding(airbagDTO.getFixingRounding())
                .setSettlementDateCalendar(airbagDTO.getSettlementDateCalendar())
                .setSettlementDateConv(airbagDTO.getSettlementDateConv())
                .setSettlementDateOffset(airbagDTO.getSettlementDateOffset())
                .setSettlementDate(terminationDate)
                .setOptionType(DictConstant.CallOrPut.Call)
                .setLegId("leg01")
                .setOptionEntitlement(String.valueOf(realnotional1 / Double.parseDouble(underlyers.get(0).getSpotPrice())))
                .setDaycounter("BUSINESS/252")
                .setKnock(
                        new Knock()
                                .setTrigger(
                                        new Trigger()
                                                .setLevelPercentage(knockIn.getTriggerRate())
                                                .setType(knockIn.getTriggerLevelInclude() == "1" ? TriggerTypeEnum.EqualOrGreater.getCode() : TriggerTypeEnum.Greater.getCode()))
                                .setObserveDates(JSON.parseObject(s, ObserveDates.class))
                                .setPaymentDate(terminationDate)
                                .setPaymentAmountPecentage("0")
                                .setPaymentDateCalendar(airbagDTO.getPaymentDateCalendar())
                                .setPaymentDateConv(airbagDTO.getSettlementDateConv())
                                .setPayStyle(payStyleEnum.Deferred.getCode())
                                .setObserveType("Close")
                                .setPaymentDateOffset(airbagDTO.getSettlementDateOffset())

                )
                .setPeriodOfAccrualInterestAdjust(airbagDTO.getPeriodOfAccrualInterestAdjust())
                .setParticipationRate("1")
                .setStrikePercentage(unKnockIn.getLowerStrikeRate())
                .setNumberOfOptions(airbagDTO.getNumberOfOptions())
        ;
        /*
        * 类型：Down-Out-Call Option
          方向：卖出
          障碍价格：敲入价格
          行权价格：高行权价格
          补偿金额：0
          有效名义本金（非年化）：名义本金*未敲入参与率
          有效名义本金（年化）：名义本金*未敲入参与率*计息天数/365
        * */
        Double realnotional2 = Double.parseDouble(unKnockIn.getParticipationRate()) * notional * year;
        barrierOption2
                .setRealnotional(String.valueOf(realnotional2))
                .setProductType(DictConstant.OPTION_TYPE.KnockOut.getCode())
                .setUnderlyers(deepCopy(underlyers))
                .setExercise(JSON.parseObject(JSON.toJSONString(airbagDTO.getExercise()), Exercise.class))
                .setMoneynessOption(airbagDTO.getMoneynessOption())
                .setFixingRounding(airbagDTO.getFixingRounding())
                .setSettlementDateCalendar(airbagDTO.getSettlementDateCalendar())
                .setSettlementDateConv(airbagDTO.getSettlementDateConv())
                .setSettlementDateOffset(airbagDTO.getSettlementDateOffset())
                .setSettlementDate(terminationDate)
                .setOptionType(DictConstant.CallOrPut.Call)
                .setLegId("leg02")
                .setOptionEntitlement(String.valueOf(realnotional2 / Double.parseDouble(underlyers.get(0).getSpotPrice())))
                .setDaycounter("BUSINESS/252")
                .setKnock(
                        new Knock()
                                .setTrigger(
                                        new Trigger()
                                                .setLevelPercentage(knockIn.getTriggerRate())
                                                .setType(knockIn.getTriggerLevelInclude() == "1" ? TriggerTypeEnum.EqualOrGreater.getCode() : TriggerTypeEnum.Greater.getCode()))
                                .setObserveDates(JSON.parseObject(s, ObserveDates.class))
                                .setPaymentDate(terminationDate)
                                .setPaymentAmountPecentage("0")
                                .setPaymentDateCalendar(airbagDTO.getPaymentDateCalendar())
                                .setPaymentDateConv(airbagDTO.getSettlementDateConv())
                                .setPayStyle(payStyleEnum.Deferred.getCode())
                                .setObserveType("Close")
                                .setPaymentDateOffset(airbagDTO.getSettlementDateOffset())

                )
                .setPeriodOfAccrualInterestAdjust(airbagDTO.getPeriodOfAccrualInterestAdjust())
                .setParticipationRate("1")
                .setStrikePercentage(unKnockIn.getUpperStrikeRate())
                .setNumberOfOptions(airbagDTO.getNumberOfOptions())
        ;
        /*
        类型：Down-In-Call Option
        方向：买入
        障碍价格：敲入价格
        行权价格：低行权价格
        补偿金额：0
        有效名义本金（非年化）：名义本金*未敲入参与率
        有效名义本金（年化）：名义本金*敲入参与率*计息天数/365*/
        Double realnotional3 = Double.parseDouble(knockIn.getParticipationRate()) * notional * year;
        barrierOption3
                .setRealnotional(String.valueOf(Double.parseDouble(knockIn.getParticipationRate()) * notional * year))
                .setProductType(DictConstant.OPTION_TYPE.KnockIn.getCode())
                .setUnderlyers(deepCopy(underlyers))
                .setExercise(JSON.parseObject(JSON.toJSONString(airbagDTO.getExercise()), Exercise.class))
                .setMoneynessOption(airbagDTO.getMoneynessOption())
                .setFixingRounding(airbagDTO.getFixingRounding())
                .setSettlementDateCalendar(airbagDTO.getSettlementDateCalendar())
                .setSettlementDateConv(airbagDTO.getSettlementDateConv())
                .setSettlementDateOffset(airbagDTO.getSettlementDateOffset())
                .setSettlementDate(terminationDate)
                .setOptionType(DictConstant.CallOrPut.Call)
                .setLegId("leg03")
                .setOptionEntitlement(String.valueOf(realnotional3 / Double.parseDouble(underlyers.get(0).getSpotPrice())))
                .setDaycounter("BUSINESS/252")
                .setKnock(
                        new Knock()
                                .setTrigger(
                                        new Trigger()
                                                .setLevelPercentage(knockIn.getTriggerRate())
                                                .setType(knockIn.getTriggerLevelInclude() == "1" ? TriggerTypeEnum.EqualOrGreater.getCode() : TriggerTypeEnum.Greater.getCode()))
                                .setObserveDates(JSON.parseObject(s, ObserveDates.class))
                                .setPaymentDate(terminationDate)
                                .setPaymentAmountPecentage("0")
                                .setPaymentDateCalendar(airbagDTO.getPaymentDateCalendar())
                                .setPaymentDateConv(airbagDTO.getSettlementDateConv())
                                .setPayStyle(payStyleEnum.Deferred.getCode())
                                .setObserveType("Close")
                                .setPaymentDateOffset(airbagDTO.getSettlementDateOffset())

                )
                .setPeriodOfAccrualInterestAdjust(airbagDTO.getPeriodOfAccrualInterestAdjust())
                .setParticipationRate("1")
                .setStrikePercentage(unKnockIn.getLowerStrikeRate())
                .setNumberOfOptions(airbagDTO.getNumberOfOptions())
        ;
        /*
        类型：Down-In-Put Option
        方向：卖出
        障碍价格：敲入价格
        行权价格：低行权价格
        补偿金额：0
        有效名义本金（非年化）：名义本金*敲入参与率
        有效名义本金（年化）：名义本金*敲入参与率*计息天数/365*/
        Double realnotional4 = Double.parseDouble(knockIn.getParticipationRate()) * notional * year;
        barrierOption4
                .setRealnotional(String.valueOf(realnotional4))
                .setProductType(DictConstant.OPTION_TYPE.KnockIn.getCode())
                .setUnderlyers(deepCopy(underlyers))
                .setExercise(JSON.parseObject(JSON.toJSONString(airbagDTO.getExercise()), Exercise.class))
                .setMoneynessOption(airbagDTO.getMoneynessOption())
                .setFixingRounding(airbagDTO.getFixingRounding())
                .setSettlementDateCalendar(airbagDTO.getSettlementDateCalendar())
                .setSettlementDateConv(airbagDTO.getSettlementDateConv())
                .setSettlementDateOffset(airbagDTO.getSettlementDateOffset())
                .setSettlementDate(terminationDate)
                .setOptionType(DictConstant.CallOrPut.Put)
                .setLegId("leg04")
                .setOptionEntitlement(String.valueOf(realnotional4 / Double.parseDouble(underlyers.get(0).getSpotPrice())))
                .setDaycounter("BUSINESS/252")
                .setKnock(
                        new Knock()
                                .setTrigger(
                                        new Trigger()
                                                .setLevelPercentage(knockIn.getTriggerRate())
                                                .setType(knockIn.getTriggerLevelInclude() == "1" ? TriggerTypeEnum.EqualOrLess.getCode() : TriggerTypeEnum.Less.getCode()))
                                .setObserveDates(JSON.parseObject(s, ObserveDates.class))
                                .setPaymentDate(terminationDate)
                                .setPaymentAmountPecentage("0")
                                .setPaymentDateCalendar(airbagDTO.getPaymentDateCalendar())
                                .setPaymentDateConv(airbagDTO.getSettlementDateConv())
                                .setPayStyle(payStyleEnum.Deferred.getCode())
                                .setObserveType("Close")
                                .setPaymentDateOffset(airbagDTO.getSettlementDateOffset())

                )
                .setPeriodOfAccrualInterestAdjust(airbagDTO.getPeriodOfAccrualInterestAdjust())
                .setParticipationRate("1")
                .setStrikePercentage(unKnockIn.getLowerStrikeRate())
                .setNumberOfOptions(airbagDTO.getNumberOfOptions())
        ;

        JSONArray customLegs = new JSONArray();
        customLegs.add(barrierOption1);
        customLegs.add(barrierOption2);
        customLegs.add(barrierOption3);
        customLegs.add(barrierOption4);
        return customLegs;
    }

    /*
     * uncap  上端不封顶  3个障碍
     * */
    private JSONArray generateUnCap(JSONObject termsheet, AirbagDTO airbagDTO) {
        BarrierOption barrierOption1 = new BarrierOption();
        BarrierOption barrierOption2 = new BarrierOption();
        BarrierOption barrierOption3 = new BarrierOption();
        KnockIn knockIn = airbagDTO.getKnockIn();
        UnKnockIn unKnockIn = airbagDTO.getUnKnockIn();
        Double notional = Double.valueOf(termsheet.get("notional").toString());
        String effectiveDate = termsheet.get("effectiveDate").toString();
        String terminationDate = termsheet.get("terminationDate").toString();
        List<Underlyers> underlyers = airbagDTO.getUnderlyers();
        underlyers.get(0).setFixingDate(terminationDate);

        ObserveDates observeDates = new ObserveDates()
                .setCalendar(airbagDTO.getPaymentDateCalendar())
                .setEndDateConv(airbagDTO.getSettlementDateConv())
                .setEndDate(terminationDate)
                .setStartDate(effectiveDate)
                .setStartDateConv(airbagDTO.getSettlementDateConv())
                .setFrequency(knockIn.getScheduleType());
        String s = JSON.toJSONString(observeDates);

        Double year = 1.0;
        if ("1".equals(airbagDTO.getMoneynessOption())) {
            Integer term = airbagDTO.getTerm();
            year = term / 365.0;
        }

        /*
        *
        * 结构一：障碍期权
            类型：Down-Out-Call Option
            方向：买入
            障碍价格：敲入价格
            行权价格：行权价格
            补偿金额：0
            有效名义本金（非年化）：名义本金*未敲入参与率
            有效名义本金（年化）：名义本金*未敲入参与率*计息天数/365

        * */
        Double realnotional1 = Double.parseDouble(unKnockIn.getParticipationRate()) * notional * year;
        barrierOption1
                /* 有效名义本金（非年化）：名义本金*未敲入参与率
                 有效名义本金（年化）：名义本金*未敲入参与率*计息天数/365*/
                .setRealnotional(String.valueOf(realnotional1))
                .setProductType(DictConstant.OPTION_TYPE.KnockOut.getCode())
                .setUnderlyers(deepCopy(underlyers))
                .setExercise(JSON.parseObject(JSON.toJSONString(airbagDTO.getExercise()), Exercise.class))
                .setMoneynessOption(airbagDTO.getMoneynessOption())
                .setFixingRounding(airbagDTO.getFixingRounding())
                .setSettlementDateCalendar(airbagDTO.getSettlementDateCalendar())
                .setSettlementDateConv(airbagDTO.getSettlementDateConv())
                .setSettlementDateOffset(airbagDTO.getSettlementDateOffset())
                .setSettlementDate(terminationDate)
                .setOptionType(DictConstant.CallOrPut.Call)
                .setLegId("leg01")
                .setOptionEntitlement(String.valueOf(realnotional1 / Double.parseDouble(underlyers.get(0).getSpotPrice())))
                .setDaycounter("BUSINESS/252")
                .setKnock(
                        new Knock()
                                .setTrigger(
                                        new Trigger()
//                                        障碍价格：敲入价格
                                                .setLevelPercentage(knockIn.getTriggerRate())
                                                .setType(knockIn.getTriggerLevelInclude() == "1" ? TriggerTypeEnum.EqualOrGreater.getCode() : TriggerTypeEnum.Greater.getCode()))
                                .setObserveDates(JSON.parseObject(s, ObserveDates.class))
                                .setPaymentDate(terminationDate)
                                .setPaymentAmountPecentage("0")
                                .setPaymentDateCalendar(airbagDTO.getPaymentDateCalendar())
                                .setPaymentDateConv(airbagDTO.getSettlementDateConv())
                                .setPayStyle(payStyleEnum.Deferred.getCode())
                                .setObserveType("Close")
                                .setPaymentDateOffset(airbagDTO.getSettlementDateOffset())

                )
                .setPeriodOfAccrualInterestAdjust(airbagDTO.getPeriodOfAccrualInterestAdjust())
                .setParticipationRate("1")
//                行权价格：行权价格
                .setStrikePercentage(unKnockIn.getStrikeRate())
                .setNumberOfOptions(airbagDTO.getNumberOfOptions())
        ;
        /*
        * 结构二：障碍期权
            类型：Down-In-Call Option
            方向：买入
            障碍价格：敲入价格
            行权价格：行权价格
            补偿金额：0
            有效名义本金（非年化）：名义本金*敲入参与率
            有效名义本金（年化）：名义本金*敲入参与率*计息天数/365

        * */
        Double realnotional2 = Double.parseDouble(knockIn.getParticipationRate()) * notional * year;
        barrierOption2
                /*有效名义本金（非年化）：名义本金*敲入参与率
            有效名义本金（年化）：名义本金*敲入参与率*计息天数/365*/
                .setRealnotional(String.valueOf(realnotional2))
                .setProductType(DictConstant.OPTION_TYPE.KnockIn.getCode())
                .setUnderlyers(deepCopy(underlyers))
                .setExercise(JSON.parseObject(JSON.toJSONString(airbagDTO.getExercise()), Exercise.class))
                .setMoneynessOption(airbagDTO.getMoneynessOption())
                .setFixingRounding(airbagDTO.getFixingRounding())
                .setSettlementDateCalendar(airbagDTO.getSettlementDateCalendar())
                .setSettlementDateConv(airbagDTO.getSettlementDateConv())
                .setSettlementDateOffset(airbagDTO.getSettlementDateOffset())
                .setSettlementDate(terminationDate)
                .setOptionType(DictConstant.CallOrPut.Call)
                .setLegId("leg02")
                .setOptionEntitlement(String.valueOf(realnotional2 / Double.parseDouble(underlyers.get(0).getSpotPrice())))
                .setDaycounter("BUSINESS/252")
                .setKnock(
                        new Knock()
                                .setTrigger(
                                        new Trigger()
                                                /*障碍价格：敲入价格*/
                                                .setLevelPercentage(knockIn.getTriggerRate())
                                                .setType(knockIn.getTriggerLevelInclude() == "1" ? TriggerTypeEnum.EqualOrGreater.getCode() : TriggerTypeEnum.Greater.getCode()))
                                .setObserveDates(JSON.parseObject(s, ObserveDates.class))
                                .setPaymentDate(terminationDate)
                                .setPaymentAmountPecentage("0")
                                .setPaymentDateCalendar(airbagDTO.getPaymentDateCalendar())
                                .setPaymentDateConv(airbagDTO.getSettlementDateConv())
                                .setPayStyle(payStyleEnum.Deferred.getCode())
                                .setObserveType("Close")
                                .setPaymentDateOffset(airbagDTO.getSettlementDateOffset())

                )
                .setPeriodOfAccrualInterestAdjust(airbagDTO.getPeriodOfAccrualInterestAdjust())
                .setParticipationRate("1")
                /*行权价格：行权价格*/
                .setStrikePercentage(unKnockIn.getStrikeRate())
                .setNumberOfOptions(airbagDTO.getNumberOfOptions())
        ;
        /*
        结构三：障碍期权
        类型：Down-In-Put Option
        方向：卖出
        障碍价格：敲入价格
        行权价格：行权价格
        补偿金额：0
        有效名义本金（非年化）：名义本金*敲入参与率
        有效名义本金（年化）：名义本金*敲入参与率*计息天数/365
*/
        Double realnotional3 = Double.parseDouble(knockIn.getParticipationRate()) * notional * year;
        barrierOption3
                .setRealnotional(String.valueOf(realnotional3))
                .setProductType(DictConstant.OPTION_TYPE.KnockIn.getCode())
                .setUnderlyers(deepCopy(underlyers))
                .setExercise(JSON.parseObject(JSON.toJSONString(airbagDTO.getExercise()), Exercise.class))
                .setMoneynessOption(airbagDTO.getMoneynessOption())
                .setFixingRounding(airbagDTO.getFixingRounding())
                .setSettlementDateCalendar(airbagDTO.getSettlementDateCalendar())
                .setSettlementDateConv(airbagDTO.getSettlementDateConv())
                .setSettlementDateOffset(airbagDTO.getSettlementDateOffset())
                .setSettlementDate(terminationDate)
                .setOptionType(DictConstant.CallOrPut.Put)
                .setLegId("leg03")
                .setOptionEntitlement(String.valueOf(realnotional3 / Double.parseDouble(underlyers.get(0).getSpotPrice())))
                .setDaycounter("BUSINESS/252")
                .setKnock(
                        new Knock()
                                .setTrigger(
                                        new Trigger()
                                                /* 障碍价格：敲入价格*/
                                                .setLevelPercentage(knockIn.getTriggerRate())
                                                .setType(knockIn.getTriggerLevelInclude() == "1" ? TriggerTypeEnum.EqualOrGreater.getCode() : TriggerTypeEnum.Greater.getCode()))
                                .setObserveDates(JSON.parseObject(s, ObserveDates.class))
                                .setPaymentDate(terminationDate)
                                .setPaymentAmountPecentage("0")
                                .setPaymentDateCalendar(airbagDTO.getPaymentDateCalendar())
                                .setPaymentDateConv(airbagDTO.getSettlementDateConv())
                                .setPayStyle(payStyleEnum.Deferred.getCode())
                                .setObserveType("Close")
                                .setPaymentDateOffset(airbagDTO.getSettlementDateOffset())

                )
                .setPeriodOfAccrualInterestAdjust(airbagDTO.getPeriodOfAccrualInterestAdjust())
                .setParticipationRate("1")
                /*行权价格：行权价格*/
                .setStrikePercentage(unKnockIn.getStrikeRate())
                .setNumberOfOptions(airbagDTO.getNumberOfOptions())
        ;
        JSONArray customLegs = new JSONArray();
        customLegs.add(barrierOption1);
        customLegs.add(barrierOption2);
        customLegs.add(barrierOption3);
        return customLegs;
    }


}
